package com.xinfan.tank;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

/**
 * @Author xin
 * @Date 2022/5/31 9:41
 * @Version 1.0
 */
public class DrawCircle extends JFrame{

    private MyPanel mp ;

    public static void main(String[] args) {

        new DrawCircle();


    }
    public DrawCircle(){
        mp = new MyPanel();

        //将面板放入窗口
        this.add(mp);
        //点击小红叉叉退出程序
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设置窗口大小
        this.setSize(1000,1000);
        this.setVisible(true);
    }

}

class MyPanel extends JPanel {

    @Override
    public void paint(Graphics g) {//初始化时会被默认调用一次
        super.paint(g);//初始化画板
        g.drawOval(20,20,100,100);

        URL resource = DrawCircle.class.getResource("1.png");

        System.out.println(resource);
        Image image = Toolkit.getDefaultToolkit().getImage(DrawCircle.class.getResource("1.png"));
        g.drawImage(image,50,50,691,372,this);

        g.setFont(new Font("宋体",Font.BOLD,13));

        g.drawString("123",40,40);//坐标为字符的左下角


    }
}
